<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Ikatan Perempuan Positif Indonesia (IPPI) Email class.
 *
 * @class ippi_email
 * @author Iqbal
 */
class ippi_email 
{
	var $CI;
    
	/**
	 * Constructor - Sets up the object properties.
	 */
	function __construct()
    {
        $this->CI       =& get_instance();
        require_once SWIFT_MAILSERVER;
	}
	
    /**
	 * Send email function.
	 *
     * @param string    $to         (Required)  To email destination
     * @param string    $subject    (Required)  Subject of email
     * @param string    $message    (Required)  Message of email
     * @param string    $from       (Optional)  From email
     * @param string    $from_name  (Optional)  From name email
	 * @return Mixed
	 */
	function send($to, $subject, $message, $from = '', $from_name = ''){
		try{
            //Create the Transport
            $transport  = Swift_MailTransport::newInstance();
            //Create the message
            $mail       = Swift_Message::newInstance();
            //Give the message a subject
            $mail->setSubject($subject)
                 ->setFrom(array($from => $from_name))
                 ->setTo($to)
                 ->setBody($message->plain)
                 ->addPart($message->html, 'text/html');
		}catch (Exception $e){
			return 'failed to gather MAILDATA';
		}
        
        //Create the Mailer using your created Transport
        $mailer     = Swift_Mailer::newInstance($transport);
        //Send the message
        $result     = $mailer->send($mail);	
        
		return $result;
	}
    
    /**
	 * Send email order function.
	 *
     * @param   Object  $data       (Required)  Data of Order
	 * @return  Mixed
	 */
    function send_email_order($to, $data){ 
        if ( !$to ) return false;
        if ( !$data ) return false;
        
        $pesan_plain        = '';
        $pesan_html         = '';

        $message            = new stdClass();
        $message->plain     = $pesan_plain;
        $message->html      = $pesan_html;

        $send_order         = $this->send($to, 'Data Pesanan IPPI', $message, 'ippi.indonesia@yahoo.com ', 'IPPI Indonesia' );
        
        if($send_order){
            return true;
        }
        return false;
    }
}

/*
CHANGELOG
---------
Insert new changelog at the top of the list.
-----------------------------------------------
Version	YYYY/MM/DD  Person Name		Description
-----------------------------------------------
1.0.0   2014/11/11  Iqbal           - Created this changelog
*/